{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.8.3 64-bit (conda)",
   "metadata": {
    "interpreter": {
     "hash": "513dc2e41d739bb2c947903f3c0bbf636d03aa53ab50e61c694a27481c81805e"
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('..')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [],
   "source": [
    "from configure.settings import DBSelector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "'c:\\\\git\\\\stock\\\\notebook'"
      ]
     },
     "metadata": {},
     "execution_count": 57
    }
   ],
   "source": [
    "import os\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [],
   "source": [
    "db = DBSelector().mongo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc = db['db_parker']['deal_company']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "result=[]\n",
    "for item in doc.find({},{'com_des':0,'closure_type':0}):\n",
    "    del item['_id']\n",
    "    result.append(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "23200"
      ]
     },
     "metadata": {},
     "execution_count": 117
    }
   ],
   "source": [
    "len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "error",
     "ename": "TypeError",
     "evalue": "unhashable type: 'dict'",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-8-11e1056f4cc7>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mno_dup_result\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'dict'"
     ]
    }
   ],
   "source": [
    "no_dup_result = list(set(result))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "{'com_name': '米聊',\n",
       " 'born': '2011-01-01',\n",
       " 'cat_name': '社交网络',\n",
       " 'closure_type': [{'id': 4, 'name': '业务调整', 'p_id': 21}],\n",
       " 'close': '2021-02-19',\n",
       " 'com_prov': '北京',\n",
       " 'live_time': 3702,\n",
       " 'total_money': None,\n",
       " 'com_des': '米聊是一个手机聊天通信工具及社交网络，小米公司旗下产品。'}"
      ]
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "result[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "        com_name        born cat_name       close com_prov  live_time  \\\n",
       "0             米聊  2011-01-01     社交网络  2021-02-19       北京       3702   \n",
       "1           虾米音乐  2007-10-01     文娱传媒  2021-02-05       浙江       4876   \n",
       "2           悟空问答  2017-01-01     文娱传媒  2021-02-03       北京       1494   \n",
       "3           盼达用车  2015-05-01     汽车交通  2021-02-01       重庆       2103   \n",
       "4  TT直播健身-VIPFIT  2018-07-01     体育运动  2021-01-19       北京        933   \n",
       "\n",
       "   total_money  \n",
       "0          NaN  \n",
       "1      11600.0  \n",
       "2          NaN  \n",
       "3       1575.0  \n",
       "4       2300.0  "
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>米聊</td>\n      <td>2011-01-01</td>\n      <td>社交网络</td>\n      <td>2021-02-19</td>\n      <td>北京</td>\n      <td>3702</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>虾米音乐</td>\n      <td>2007-10-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-05</td>\n      <td>浙江</td>\n      <td>4876</td>\n      <td>11600.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>悟空问答</td>\n      <td>2017-01-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-03</td>\n      <td>北京</td>\n      <td>1494</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>盼达用车</td>\n      <td>2015-05-01</td>\n      <td>汽车交通</td>\n      <td>2021-02-01</td>\n      <td>重庆</td>\n      <td>2103</td>\n      <td>1575.0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>TT直播健身-VIPFIT</td>\n      <td>2018-07-01</td>\n      <td>体育运动</td>\n      <td>2021-01-19</td>\n      <td>北京</td>\n      <td>933</td>\n      <td>2300.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 135
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.drop_duplicates(['com_name','born'],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "14510"
      ]
     },
     "metadata": {},
     "execution_count": 120
    }
   ],
   "source": [
    "len(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "        com_name        born cat_name  \\\n",
       "0             米聊  2011-01-01     社交网络   \n",
       "1           虾米音乐  2007-10-01     文娱传媒   \n",
       "2           悟空问答  2017-01-01     文娱传媒   \n",
       "3           盼达用车  2015-05-01     汽车交通   \n",
       "4  TT直播健身-VIPFIT  2018-07-01     体育运动   \n",
       "\n",
       "                                        closure_type       close com_prov  \\\n",
       "0            [{'id': 4, 'name': '业务调整', 'p_id': 21}]  2021-02-19       北京   \n",
       "1  [{'id': 4, 'name': '业务调整', 'p_id': 21}, {'id':...  2021-02-05       浙江   \n",
       "2            [{'id': 4, 'name': '业务调整', 'p_id': 21}]  2021-02-03       北京   \n",
       "3  [{'id': 11, 'name': '烧钱', 'p_id': 24}, {'id': ...  2021-02-01       重庆   \n",
       "4  [{'id': 12, 'name': '现金流断裂', 'p_id': 24}, {'id...  2021-01-19       北京   \n",
       "\n",
       "   live_time  total_money                                            com_des  \n",
       "0       3702          NaN                       米聊是一个手机聊天通信工具及社交网络，小米公司旗下产品。  \n",
       "1       4876      11600.0  虾米音乐是一款提供各类音乐的音频资源聚合平台，用户可以在平台上查找、收听自己喜欢的音乐内容，...  \n",
       "2       1494          NaN  悟空问答是今日头条旗下的问答产品，明星专家为你答疑解惑，个性化推荐热点讨论，打发时间利器，北...  \n",
       "3       2103       1575.0  盼达用车是一家新能源汽车共享租赁平台，专注于提供分时租赁、专车租赁、企事业机构团体长租等汽车...  \n",
       "4        933       2300.0  TT直播健身（VIPFIT）是一个在线真人健身私教服务平台，根据个人身体基础和环境为用户量身...  "
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>closure_type</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n      <th>com_des</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>米聊</td>\n      <td>2011-01-01</td>\n      <td>社交网络</td>\n      <td>[{'id': 4, 'name': '业务调整', 'p_id': 21}]</td>\n      <td>2021-02-19</td>\n      <td>北京</td>\n      <td>3702</td>\n      <td>NaN</td>\n      <td>米聊是一个手机聊天通信工具及社交网络，小米公司旗下产品。</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>虾米音乐</td>\n      <td>2007-10-01</td>\n      <td>文娱传媒</td>\n      <td>[{'id': 4, 'name': '业务调整', 'p_id': 21}, {'id':...</td>\n      <td>2021-02-05</td>\n      <td>浙江</td>\n      <td>4876</td>\n      <td>11600.0</td>\n      <td>虾米音乐是一款提供各类音乐的音频资源聚合平台，用户可以在平台上查找、收听自己喜欢的音乐内容，...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>悟空问答</td>\n      <td>2017-01-01</td>\n      <td>文娱传媒</td>\n      <td>[{'id': 4, 'name': '业务调整', 'p_id': 21}]</td>\n      <td>2021-02-03</td>\n      <td>北京</td>\n      <td>1494</td>\n      <td>NaN</td>\n      <td>悟空问答是今日头条旗下的问答产品，明星专家为你答疑解惑，个性化推荐热点讨论，打发时间利器，北...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>盼达用车</td>\n      <td>2015-05-01</td>\n      <td>汽车交通</td>\n      <td>[{'id': 11, 'name': '烧钱', 'p_id': 24}, {'id': ...</td>\n      <td>2021-02-01</td>\n      <td>重庆</td>\n      <td>2103</td>\n      <td>1575.0</td>\n      <td>盼达用车是一家新能源汽车共享租赁平台，专注于提供分时租赁、专车租赁、企事业机构团体长租等汽车...</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>TT直播健身-VIPFIT</td>\n      <td>2018-07-01</td>\n      <td>体育运动</td>\n      <td>[{'id': 12, 'name': '现金流断裂', 'p_id': 24}, {'id...</td>\n      <td>2021-01-19</td>\n      <td>北京</td>\n      <td>933</td>\n      <td>2300.0</td>\n      <td>TT直播健身（VIPFIT）是一个在线真人健身私教服务平台，根据个人身体基础和环境为用户量身...</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 24
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "企业服务 76\n体育运动 4\n先进制造 5\n农业 6\n区块链 14\n医疗健康 18\n工具软件 21\n广告营销 16\n房产服务 9\n教育 37\n文娱传媒 43\n旅游 20\n智能硬件 11\n本地生活 34\n汽车交通 25\n游戏 29\n物流 4\n生产制造 2\n电子商务 71\n社交网络 17\n金融 68\n"
     ]
    }
   ],
   "source": [
    "for cate,_ in df.groupby('cat_name'):\n",
    "    print(cate,len(_))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [],
   "source": [
    "def close_year(x):\n",
    "    return int(x[:4])\n",
    "    # return x[:-3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['close_year']=df['close'].apply(close_year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['born_year']=df['born'].apply(close_year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "        com_name        born cat_name       close com_prov  live_time  \\\n",
       "0             米聊  2011-01-01     社交网络  2021-02-19       北京       3702   \n",
       "1           虾米音乐  2007-10-01     文娱传媒  2021-02-05       浙江       4876   \n",
       "2           悟空问答  2017-01-01     文娱传媒  2021-02-03       北京       1494   \n",
       "3           盼达用车  2015-05-01     汽车交通  2021-02-01       重庆       2103   \n",
       "4  TT直播健身-VIPFIT  2018-07-01     体育运动  2021-01-19       北京        933   \n",
       "\n",
       "   total_money close_year  \n",
       "0          NaN    2021-02  \n",
       "1      11600.0    2021-02  \n",
       "2          NaN    2021-02  \n",
       "3       1575.0    2021-02  \n",
       "4       2300.0    2021-01  "
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n      <th>close_year</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>米聊</td>\n      <td>2011-01-01</td>\n      <td>社交网络</td>\n      <td>2021-02-19</td>\n      <td>北京</td>\n      <td>3702</td>\n      <td>NaN</td>\n      <td>2021-02</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>虾米音乐</td>\n      <td>2007-10-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-05</td>\n      <td>浙江</td>\n      <td>4876</td>\n      <td>11600.0</td>\n      <td>2021-02</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>悟空问答</td>\n      <td>2017-01-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-03</td>\n      <td>北京</td>\n      <td>1494</td>\n      <td>NaN</td>\n      <td>2021-02</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>盼达用车</td>\n      <td>2015-05-01</td>\n      <td>汽车交通</td>\n      <td>2021-02-01</td>\n      <td>重庆</td>\n      <td>2103</td>\n      <td>1575.0</td>\n      <td>2021-02</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>TT直播健身-VIPFIT</td>\n      <td>2018-07-01</td>\n      <td>体育运动</td>\n      <td>2021-01-19</td>\n      <td>北京</td>\n      <td>933</td>\n      <td>2300.0</td>\n      <td>2021-01</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 123
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "metadata": {},
   "outputs": [],
   "source": [
    "area = list(df['cat_name'].unique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "['社交网络',\n",
       " '文娱传媒',\n",
       " '汽车交通',\n",
       " '体育运动',\n",
       " '企业服务',\n",
       " '游戏',\n",
       " '广告营销',\n",
       " '电子商务',\n",
       " '教育',\n",
       " '本地生活',\n",
       " '金融',\n",
       " '房产服务',\n",
       " '智能硬件',\n",
       " '物流',\n",
       " '医疗健康',\n",
       " '工具软件',\n",
       " '旅游',\n",
       " '农业',\n",
       " '区块链',\n",
       " '先进制造',\n",
       " '生产制造']"
      ]
     },
     "metadata": {},
     "execution_count": 43
    }
   ],
   "source": [
    "area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [],
   "source": [
    "for item in area:\n",
    "    df[item]=df['cat_name'].str.contains(item).apply(lambda x:1 if x else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "        com_name        born cat_name       close com_prov  live_time  \\\n",
       "0             米聊  2011-01-01     社交网络  2021-02-19       北京       3702   \n",
       "1           虾米音乐  2007-10-01     文娱传媒  2021-02-05       浙江       4876   \n",
       "2           悟空问答  2017-01-01     文娱传媒  2021-02-03       北京       1494   \n",
       "3           盼达用车  2015-05-01     汽车交通  2021-02-01       重庆       2103   \n",
       "4  TT直播健身-VIPFIT  2018-07-01     体育运动  2021-01-19       北京        933   \n",
       "\n",
       "   total_money close_year  社交网络  文娱传媒  ...  房产服务  智能硬件  物流  医疗健康  工具软件  旅游  \\\n",
       "0          NaN    2021-02     1     0  ...     0     0   0     0     0   0   \n",
       "1      11600.0    2021-02     0     1  ...     0     0   0     0     0   0   \n",
       "2          NaN    2021-02     0     1  ...     0     0   0     0     0   0   \n",
       "3       1575.0    2021-02     0     0  ...     0     0   0     0     0   0   \n",
       "4       2300.0    2021-01     0     0  ...     0     0   0     0     0   0   \n",
       "\n",
       "   农业  区块链  先进制造  生产制造  \n",
       "0   0    0     0     0  \n",
       "1   0    0     0     0  \n",
       "2   0    0     0     0  \n",
       "3   0    0     0     0  \n",
       "4   0    0     0     0  \n",
       "\n",
       "[5 rows x 29 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n      <th>close_year</th>\n      <th>社交网络</th>\n      <th>文娱传媒</th>\n      <th>...</th>\n      <th>房产服务</th>\n      <th>智能硬件</th>\n      <th>物流</th>\n      <th>医疗健康</th>\n      <th>工具软件</th>\n      <th>旅游</th>\n      <th>农业</th>\n      <th>区块链</th>\n      <th>先进制造</th>\n      <th>生产制造</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>米聊</td>\n      <td>2011-01-01</td>\n      <td>社交网络</td>\n      <td>2021-02-19</td>\n      <td>北京</td>\n      <td>3702</td>\n      <td>NaN</td>\n      <td>2021-02</td>\n      <td>1</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>虾米音乐</td>\n      <td>2007-10-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-05</td>\n      <td>浙江</td>\n      <td>4876</td>\n      <td>11600.0</td>\n      <td>2021-02</td>\n      <td>0</td>\n      <td>1</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>悟空问答</td>\n      <td>2017-01-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-03</td>\n      <td>北京</td>\n      <td>1494</td>\n      <td>NaN</td>\n      <td>2021-02</td>\n      <td>0</td>\n      <td>1</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>盼达用车</td>\n      <td>2015-05-01</td>\n      <td>汽车交通</td>\n      <td>2021-02-01</td>\n      <td>重庆</td>\n      <td>2103</td>\n      <td>1575.0</td>\n      <td>2021-02</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>TT直播健身-VIPFIT</td>\n      <td>2018-07-01</td>\n      <td>体育运动</td>\n      <td>2021-01-19</td>\n      <td>北京</td>\n      <td>933</td>\n      <td>2300.0</td>\n      <td>2021-01</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 29 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 126
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [],
   "source": [
    "industry_df = df.loc[:,area]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "   社交网络  文娱传媒  汽车交通  体育运动  企业服务  游戏  广告营销  电子商务  教育  本地生活  ...  房产服务  智能硬件  \\\n",
       "0     1     0     0     0     0   0     0     0   0     0  ...     0     0   \n",
       "1     0     1     0     0     0   0     0     0   0     0  ...     0     0   \n",
       "2     0     1     0     0     0   0     0     0   0     0  ...     0     0   \n",
       "3     0     0     1     0     0   0     0     0   0     0  ...     0     0   \n",
       "4     0     0     0     1     0   0     0     0   0     0  ...     0     0   \n",
       "\n",
       "   物流  医疗健康  工具软件  旅游  农业  区块链  先进制造  生产制造  \n",
       "0   0     0     0   0   0    0     0     0  \n",
       "1   0     0     0   0   0    0     0     0  \n",
       "2   0     0     0   0   0    0     0     0  \n",
       "3   0     0     0   0   0    0     0     0  \n",
       "4   0     0     0   0   0    0     0     0  \n",
       "\n",
       "[5 rows x 21 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>社交网络</th>\n      <th>文娱传媒</th>\n      <th>汽车交通</th>\n      <th>体育运动</th>\n      <th>企业服务</th>\n      <th>游戏</th>\n      <th>广告营销</th>\n      <th>电子商务</th>\n      <th>教育</th>\n      <th>本地生活</th>\n      <th>...</th>\n      <th>房产服务</th>\n      <th>智能硬件</th>\n      <th>物流</th>\n      <th>医疗健康</th>\n      <th>工具软件</th>\n      <th>旅游</th>\n      <th>农业</th>\n      <th>区块链</th>\n      <th>先进制造</th>\n      <th>生产制造</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 21 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 142
    }
   ],
   "source": [
    "industry_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [],
   "source": [
    "industry_df.index=df['close_year']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "            社交网络  文娱传媒  汽车交通  体育运动  企业服务  游戏  广告营销  电子商务  教育  本地生活  ...  房产服务  \\\n",
       "close_year                                                          ...         \n",
       "2021-02        1     0     0     0     0   0     0     0   0     0  ...     0   \n",
       "2021-02        0     1     0     0     0   0     0     0   0     0  ...     0   \n",
       "2021-02        0     1     0     0     0   0     0     0   0     0  ...     0   \n",
       "2021-02        0     0     1     0     0   0     0     0   0     0  ...     0   \n",
       "2021-01        0     0     0     1     0   0     0     0   0     0  ...     0   \n",
       "\n",
       "            智能硬件  物流  医疗健康  工具软件  旅游  农业  区块链  先进制造  生产制造  \n",
       "close_year                                                 \n",
       "2021-02        0   0     0     0   0   0    0     0     0  \n",
       "2021-02        0   0     0     0   0   0    0     0     0  \n",
       "2021-02        0   0     0     0   0   0    0     0     0  \n",
       "2021-02        0   0     0     0   0   0    0     0     0  \n",
       "2021-01        0   0     0     0   0   0    0     0     0  \n",
       "\n",
       "[5 rows x 21 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>社交网络</th>\n      <th>文娱传媒</th>\n      <th>汽车交通</th>\n      <th>体育运动</th>\n      <th>企业服务</th>\n      <th>游戏</th>\n      <th>广告营销</th>\n      <th>电子商务</th>\n      <th>教育</th>\n      <th>本地生活</th>\n      <th>...</th>\n      <th>房产服务</th>\n      <th>智能硬件</th>\n      <th>物流</th>\n      <th>医疗健康</th>\n      <th>工具软件</th>\n      <th>旅游</th>\n      <th>农业</th>\n      <th>区块链</th>\n      <th>先进制造</th>\n      <th>生产制造</th>\n    </tr>\n    <tr>\n      <th>close_year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2021-02</th>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-02</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-02</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-02</th>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2021-01</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 21 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 145
    }
   ],
   "source": [
    "industry_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "_industry_df = industry_df.groupby('close_year').sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "            社交网络  文娱传媒  汽车交通  体育运动  企业服务  游戏  广告营销  电子商务  教育  本地生活  ...  房产服务  \\\n",
       "close_year                                                          ...         \n",
       "2006-07        0     0     0     0     1   0     0     0   1     0  ...     0   \n",
       "2006-08        0     0     0     0     1   0     0     0   0     0  ...     0   \n",
       "2006-12        1     1     0     0     0   0     0     1   0     0  ...     0   \n",
       "2007-04        0     0     0     0     1   0     0     0   0     0  ...     0   \n",
       "2007-07        0     1     0     0     0   0     0     0   1     0  ...     0   \n",
       "\n",
       "            智能硬件  物流  医疗健康  工具软件  旅游  农业  区块链  先进制造  生产制造  \n",
       "close_year                                                 \n",
       "2006-07        0   0     0     0   0   0    0     0     0  \n",
       "2006-08        0   0     1     1   0   0    0     0     0  \n",
       "2006-12        0   0     1     0   0   0    0     0     0  \n",
       "2007-04        0   0     0     0   0   0    0     0     0  \n",
       "2007-07        0   0     1     0   0   0    0     0     0  \n",
       "\n",
       "[5 rows x 21 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>社交网络</th>\n      <th>文娱传媒</th>\n      <th>汽车交通</th>\n      <th>体育运动</th>\n      <th>企业服务</th>\n      <th>游戏</th>\n      <th>广告营销</th>\n      <th>电子商务</th>\n      <th>教育</th>\n      <th>本地生活</th>\n      <th>...</th>\n      <th>房产服务</th>\n      <th>智能硬件</th>\n      <th>物流</th>\n      <th>医疗健康</th>\n      <th>工具软件</th>\n      <th>旅游</th>\n      <th>农业</th>\n      <th>区块链</th>\n      <th>先进制造</th>\n      <th>生产制造</th>\n    </tr>\n    <tr>\n      <th>close_year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2006-07</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2006-08</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2006-12</th>\n      <td>1</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2007-04</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>2007-07</th>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>1</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 21 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 132
    }
   ],
   "source": [
    "_industry_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [],
   "source": [
    "_industry_df.T.to_excel('close_company_year.xlsx',encoding='utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_1 = pd.DataFrame(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_1.drop_duplicates(['com_name','born'],inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_1['close_year']=df_1['close'].apply(close_year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_1['born_year']=df_1['born'].apply(close_year)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "            com_name        born cat_name       close com_prov  live_time  \\\n",
       "0                 米聊  2011-01-01     社交网络  2021-02-19       北京       3702   \n",
       "1               虾米音乐  2007-10-01     文娱传媒  2021-02-05       浙江       4876   \n",
       "2               悟空问答  2017-01-01     文娱传媒  2021-02-03       北京       1494   \n",
       "3               盼达用车  2015-05-01     汽车交通  2021-02-01       重庆       2103   \n",
       "4      TT直播健身-VIPFIT  2018-07-01     体育运动  2021-01-19       北京        933   \n",
       "...              ...         ...      ...         ...      ...        ...   \n",
       "23195            阿里测  2004-01-01     工具软件  2006-08-09       浙江        951   \n",
       "23196             九极  2003-05-01     医疗健康  2006-08-08       广东       1195   \n",
       "23197         上海金略软件  2003-01-01     企业服务  2006-08-02       上海       1309   \n",
       "23198            安派克  1994-11-01     企业服务  2006-07-31       上海       4290   \n",
       "23199           辣妈育儿  2003-08-01       教育  2006-07-26       北京       1090   \n",
       "\n",
       "       total_money  close_year  born_year  \n",
       "0              NaN        2021       2011  \n",
       "1          11600.0        2021       2007  \n",
       "2              NaN        2021       2017  \n",
       "3           1575.0        2021       2015  \n",
       "4           2300.0        2021       2018  \n",
       "...            ...         ...        ...  \n",
       "23195          NaN        2006       2004  \n",
       "23196          NaN        2006       2003  \n",
       "23197          NaN        2006       2003  \n",
       "23198          NaN        2006       1994  \n",
       "23199          NaN        2006       2003  \n",
       "\n",
       "[14510 rows x 9 columns]"
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n      <th>close_year</th>\n      <th>born_year</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>米聊</td>\n      <td>2011-01-01</td>\n      <td>社交网络</td>\n      <td>2021-02-19</td>\n      <td>北京</td>\n      <td>3702</td>\n      <td>NaN</td>\n      <td>2021</td>\n      <td>2011</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>虾米音乐</td>\n      <td>2007-10-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-05</td>\n      <td>浙江</td>\n      <td>4876</td>\n      <td>11600.0</td>\n      <td>2021</td>\n      <td>2007</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>悟空问答</td>\n      <td>2017-01-01</td>\n      <td>文娱传媒</td>\n      <td>2021-02-03</td>\n      <td>北京</td>\n      <td>1494</td>\n      <td>NaN</td>\n      <td>2021</td>\n      <td>2017</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>盼达用车</td>\n      <td>2015-05-01</td>\n      <td>汽车交通</td>\n      <td>2021-02-01</td>\n      <td>重庆</td>\n      <td>2103</td>\n      <td>1575.0</td>\n      <td>2021</td>\n      <td>2015</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>TT直播健身-VIPFIT</td>\n      <td>2018-07-01</td>\n      <td>体育运动</td>\n      <td>2021-01-19</td>\n      <td>北京</td>\n      <td>933</td>\n      <td>2300.0</td>\n      <td>2021</td>\n      <td>2018</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>23195</th>\n      <td>阿里测</td>\n      <td>2004-01-01</td>\n      <td>工具软件</td>\n      <td>2006-08-09</td>\n      <td>浙江</td>\n      <td>951</td>\n      <td>NaN</td>\n      <td>2006</td>\n      <td>2004</td>\n    </tr>\n    <tr>\n      <th>23196</th>\n      <td>九极</td>\n      <td>2003-05-01</td>\n      <td>医疗健康</td>\n      <td>2006-08-08</td>\n      <td>广东</td>\n      <td>1195</td>\n      <td>NaN</td>\n      <td>2006</td>\n      <td>2003</td>\n    </tr>\n    <tr>\n      <th>23197</th>\n      <td>上海金略软件</td>\n      <td>2003-01-01</td>\n      <td>企业服务</td>\n      <td>2006-08-02</td>\n      <td>上海</td>\n      <td>1309</td>\n      <td>NaN</td>\n      <td>2006</td>\n      <td>2003</td>\n    </tr>\n    <tr>\n      <th>23198</th>\n      <td>安派克</td>\n      <td>1994-11-01</td>\n      <td>企业服务</td>\n      <td>2006-07-31</td>\n      <td>上海</td>\n      <td>4290</td>\n      <td>NaN</td>\n      <td>2006</td>\n      <td>1994</td>\n    </tr>\n    <tr>\n      <th>23199</th>\n      <td>辣妈育儿</td>\n      <td>2003-08-01</td>\n      <td>教育</td>\n      <td>2006-07-26</td>\n      <td>北京</td>\n      <td>1090</td>\n      <td>NaN</td>\n      <td>2006</td>\n      <td>2003</td>\n    </tr>\n  </tbody>\n</table>\n<p>14510 rows × 9 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 165
    }
   ],
   "source": [
    "df_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_born = df_1.groupby('born_year')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "           com_name  born  cat_name  close  com_prov  live_time  total_money  \\\n",
       "born_year                                                                      \n",
       "1981              1     1         1      1         1          1            1   \n",
       "1989              1     1         1      1         1          1            1   \n",
       "1993              4     4         4      4         4          4            0   \n",
       "1994              2     2         2      2         2          2            0   \n",
       "1995              2     2         2      2         2          2            0   \n",
       "\n",
       "           close_year  \n",
       "born_year              \n",
       "1981                1  \n",
       "1989                1  \n",
       "1993                4  \n",
       "1994                2  \n",
       "1995                2  "
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n      <th>close_year</th>\n    </tr>\n    <tr>\n      <th>born_year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1981</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1989</th>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>1993</th>\n      <td>4</td>\n      <td>4</td>\n      <td>4</td>\n      <td>4</td>\n      <td>4</td>\n      <td>4</td>\n      <td>0</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>1994</th>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>0</td>\n      <td>2</td>\n    </tr>\n    <tr>\n      <th>1995</th>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>2</td>\n      <td>0</td>\n      <td>2</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 169
    }
   ],
   "source": [
    "df_born.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "           com_name  born  cat_name  close  com_prov  live_time  total_money  \\\n",
       "born_year                                                                      \n",
       "2015           2928  2928      2928   2928      2928       2928          604   \n",
       "2016           1439  1439      1439   1439      1439       1439          232   \n",
       "2017            877   877       877    877       877        877           99   \n",
       "2018            434   434       434    434       434        434           42   \n",
       "2019             43    43        43     43        43         43            1   \n",
       "\n",
       "           close_year  \n",
       "born_year              \n",
       "2015             2928  \n",
       "2016             1439  \n",
       "2017              877  \n",
       "2018              434  \n",
       "2019               43  "
      ],
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>com_name</th>\n      <th>born</th>\n      <th>cat_name</th>\n      <th>close</th>\n      <th>com_prov</th>\n      <th>live_time</th>\n      <th>total_money</th>\n      <th>close_year</th>\n    </tr>\n    <tr>\n      <th>born_year</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2015</th>\n      <td>2928</td>\n      <td>2928</td>\n      <td>2928</td>\n      <td>2928</td>\n      <td>2928</td>\n      <td>2928</td>\n      <td>604</td>\n      <td>2928</td>\n    </tr>\n    <tr>\n      <th>2016</th>\n      <td>1439</td>\n      <td>1439</td>\n      <td>1439</td>\n      <td>1439</td>\n      <td>1439</td>\n      <td>1439</td>\n      <td>232</td>\n      <td>1439</td>\n    </tr>\n    <tr>\n      <th>2017</th>\n      <td>877</td>\n      <td>877</td>\n      <td>877</td>\n      <td>877</td>\n      <td>877</td>\n      <td>877</td>\n      <td>99</td>\n      <td>877</td>\n    </tr>\n    <tr>\n      <th>2018</th>\n      <td>434</td>\n      <td>434</td>\n      <td>434</td>\n      <td>434</td>\n      <td>434</td>\n      <td>434</td>\n      <td>42</td>\n      <td>434</td>\n    </tr>\n    <tr>\n      <th>2019</th>\n      <td>43</td>\n      <td>43</td>\n      <td>43</td>\n      <td>43</td>\n      <td>43</td>\n      <td>43</td>\n      <td>1</td>\n      <td>43</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 170
    }
   ],
   "source": [
    "df_born.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [],
   "source": [
    "born_dict ={}\n",
    "for year,sub_df in df_1.groupby('born_year'):\n",
    "    # print(year)\n",
    "    # len(sub_df['born']\n",
    "    born_dict[year]=len(sub_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "{1981: 1,\n",
       " 1989: 1,\n",
       " 1993: 4,\n",
       " 1994: 2,\n",
       " 1995: 2,\n",
       " 1996: 4,\n",
       " 1997: 3,\n",
       " 1998: 14,\n",
       " 1999: 9,\n",
       " 2000: 21,\n",
       " 2001: 23,\n",
       " 2002: 26,\n",
       " 2003: 49,\n",
       " 2004: 54,\n",
       " 2005: 78,\n",
       " 2006: 102,\n",
       " 2007: 147,\n",
       " 2008: 159,\n",
       " 2009: 266,\n",
       " 2010: 462,\n",
       " 2011: 886,\n",
       " 2012: 1367,\n",
       " 2013: 2059,\n",
       " 2014: 3050,\n",
       " 2015: 2928,\n",
       " 2016: 1439,\n",
       " 2017: 877,\n",
       " 2018: 434,\n",
       " 2019: 43}"
      ]
     },
     "metadata": {},
     "execution_count": 173
    }
   ],
   "source": [
    "born_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [],
   "source": [
    "dead_dict ={}\n",
    "for year,sub_df in df_1.groupby('close_year'):\n",
    "    # print(year)\n",
    "    # len(sub_df['born']\n",
    "    dead_dict[year]=len(sub_df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "{2006: 9,\n",
       " 2007: 12,\n",
       " 2008: 14,\n",
       " 2009: 24,\n",
       " 2010: 35,\n",
       " 2011: 54,\n",
       " 2012: 71,\n",
       " 2013: 193,\n",
       " 2014: 346,\n",
       " 2015: 1036,\n",
       " 2016: 1647,\n",
       " 2017: 2493,\n",
       " 2018: 2498,\n",
       " 2019: 5068,\n",
       " 2020: 1005,\n",
       " 2021: 5}"
      ]
     },
     "metadata": {},
     "execution_count": 175
    }
   ],
   "source": [
    "dead_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}